<template>
  <div>
    <el-dialog title="导出" :model-value="addDialogVisible" @open="handleOpen" :before-close="handleCancel" width="30%">
      <el-form :model="formData" :rules="rules" label-width="100px" ref="addForm">
        <el-form-item label="资源名:" prop="resourceName">
          <el-input v-model="formData.resourceName"></el-input>
        </el-form-item>
        <el-form-item label="标签:" prop="tag">
          <el-input v-model="formData.tag"></el-input>
        </el-form-item>
        <el-form-item label="页数:" prop="pageNum">
          <el-input type="number" v-model="formData.pageNum" min="1"></el-input>
        </el-form-item>
        <el-form-item label="页面大小:" prop="pageSize">
          <el-input type="number" v-model="formData.pageSize" min="1"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel()">取消</el-button>
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name='AddAuthority' lang='ts'>
import {reactive, ref} from 'vue';
import {ElMessage} from 'element-plus';
import {cosApi, resourceApi} from '@/api/resourceApi';
import {useUserStore} from "@/store/useUserStore";
const userStore = useUserStore();
// 新增权限对应的字段
let formData = reactive({
    resourceName: '',
    tag: '',
    pageNum: 1,
    pageSize: 10,
});

let rules = reactive({
    resourceName: [
      { required: false, message: "请输入资源名称", trigger: "blur" },
    ],
    tag: [
      { required: false, message: "请输入标签", trigger: "blur" },
    ],
    pageNum: [
      { required: false, message: "请输入资源类型", trigger: "blur" },
    ],
    pageSize: [
      { required: false, message: "请输入用户id", trigger: "blur" },
    ]
});

let addForm = ref();

defineProps<{ addDialogVisible: boolean }>();
let emitter = defineEmits(["closeDialog", "addSuccess"]);

function handleOpen() {
  // 打开对话框事件
}

function handleCancel() {
  addForm.value.resetFields();
  emitter("closeDialog");
}

async function onSubmit() {

  try {
    await resourceApi.exportExcel(formData.resourceName, formData.tag, formData.pageNum, formData.pageSize)
    ElMessage.success('导出成功');
    handleCancel();
  } catch (error) {
    ElMessage.error('导出失败，请重试');
    console.error(error);
  }
}



</script>

<style scoped></style>